<?php
$cs = Yii::app()->getClientScript();
//$cs->registerScriptFile('/javascript/ajaxloading.js');
            $this->widget('application.widgets.listicon.ListIcon',array(
                    'id'=>'package_listicon_'.$package->id,
                    'icons'=>array(
                            array('value'=>'Add cargo/Edit this package','icon'=>'ui-icon-plus','htmlOptions'=>array('href'=>CHtml::normalizeUrl(array('packing_list/updatepackage','id'=>$package->id)))),
                            array('value'=>'Remove this package','icon'=>'ui-icon-close'),
                     ),
                    'htmlOptions'=>array('style'=>'text-align: right;')
                ));
                
?>
    <div id='packages_information'>
<table>
    <tr>
        <th>
            <?php echo CHtml::encode($package->getAttributeLabel('marking')); ?>
        </th>
        <td>
            <?php echo CHtml::encode($package->marking); ?>
        </td>
        <th>
            <?php echo CHtml::encode($package->getAttributeLabel('pkg')); ?>
        </th>
        <td>
            <?php echo CHtml::encode($package->pkg); ?>
        </td>
        <th>
            <?php echo CHtml::encode($package->getAttributeLabel('wt')); ?>
        </th>
        <td>
            <?php echo CHtml::encode($package->wt); ?>
        </td>
    </tr>
    <tr>
        <th>
            <?php echo CHtml::encode($package->getAttributeLabel('length')); ?>
        </th>
        <td>
            <?php echo CHtml::encode($package->length); ?>
        </td>
        <th>
            <?php echo CHtml::encode($package->getAttributeLabel('width')); ?>
        </th>
        <td>
            <?php echo CHtml::encode($package->width); ?>
        </td>
        <th>
            <?php echo CHtml::encode($package->getAttributeLabel('height')); ?>
        </th>
        <td>
            <?php echo CHtml::encode($package->height); ?>
        </td>
    </tr>
    <tr>
        <th>
            <?php echo CHtml::encode($package->getAttributeLabel('do_list')); ?>
        </th>
        <td colspan="5" id="table_do_list_<?php echo $package->id;?>">
            <?php echo $package->current_do_list(); ?>
        </td>
    </tr>
</table>
</div>
<?php
$viewPackageURL = CHtml::normalizeUrl(array('packing_list/viewpackage'));
$script =<<<EOD
$('#table_do_list_$package->id a').each(function(){
    $(this).click(function(){
         link =$(this).attr('href');
         var cargoform = $.extend({},$.simplelogcontent,{
            afterShow:function() {
                alert('in aftershow');
            }
         });
         cargoform.show(link);
         return false;
    });
});
$('div#package_listicon_$package->id').each(function(){
    $(this).find('a:eq(0)').live('click',function(){
        var container = $(this).parent().parent();
        $(container).subcontent({
            url:$(this).attr('href'),
            data:{id:'$package->id',packing_list_id:$package->packing_list_id},
            afterShow:function(){
                $(container).find('input[type="submit"]').unbind();
                $(container).find('input[type="submit"]').bind({'click':function(){
                    var newSubmit = $.extend({},$.simplelogform,{afterSubmit:function(){
                            $(container).subcontent({
                                url:'$viewPackageURL?id=$package->id'
                            });
                        }
                    });
                    var i=0;
                    var cargo_id = [];
                    $(container).find('table#cargo_list').find('tbody').children('tr').each(function(){
                    	input = $(this).find('input:first');
                   		var name = $(input).attr("name").match(/\[[\d\w]+\]/gi);
                		var replaceName = name[1];
                        var name = $(input).attr('name').replace(replaceName,'[cargo_id]');
                        var value = $(input).attr('cargo_id');
                        cargo_id[name] = value;
                        i++;
                    });
                    newSubmit.Submit($(container).find('form'),cargo_id);
                    return false;
                    }
                });
                $(container).find('input#Cancel').click(function(){
                    $(container).subcontent({
                        url:'$viewPackageURL?id=$package->id'
                    });
                });
           }
       });
        return false;
    });
});
EOD;
$ScriptPos = (Yii::app()->request->isAjaxRequest)?CClientScript::POS_END:CClientScript::POS_READY;
$cs->registerScript('viewpackage#'.$package->id,$script,$ScriptPos);
?>